import logging
import threading
import  time
from threading import Lock
Lock=Lock()
def log_set():
    logging.basicConfig(filename='log.txt',level=logging.INFO,filemode='w+',format='%(message)s')


class testThred():
    def watch(self):

            for _ in range(10):
                with Lock:
                    logging.info('看电视')
                    time.sleep(1)

    def QQchat(self):

            for _ in range(10):
                with Lock:
                    logging.info('聊天')
                    time.sleep(1)

    def dohomework(self):
            for _ in range(10):
                with Lock:
                    logging.info('做家务')
                    time.sleep(1)

#产生一个线程对象
threadobj=testThred()
#调用日志的方法
log_set()
print('开始时间',time.asctime())
t1=threading.Thread(target=threadobj.watch)
t2=threading.Thread(target=threadobj.QQchat)
t3=threading.Thread(target=threadobj.dohomework)
t1.start()
t2.start()
t3.start()
t1.join()
t2.join()
t3.join()
print('结束时间',time.asctime())


